package com.radar.io.radar346.DataType;

import com.radar.common.GisConstants;
import com.radar.io.radar346.Product382改;
import com.radar.utils.BitConverter;

public class RSCAndVCSparse {
    Product382改 _this;

    public RSCAndVCSparse(Product382改 product382改) {
        _this = product382改;
    }

    public void parse(byte[] bytes, int index, Product382改.RealFile header) throws Exception {
        int Layers = header.realObserSec.iLiTiSaoMiaoCengShu;
        int[] Records = new int[Layers];
        double[] MaxV = new double[Layers];
        for (int i = 0; i < Layers; i++) {
            Records[i] = header.realObserSec.LayerParam[i].iCaiYangJinXiangShu;
            _this.Bins = header.realObserSec.LayerParam[i].usRefBinNumber;
        }
        _this.azi = new double[Records[0]];  //长度为每层径向数
        int h = BitConverter.toInt32(bytes, index);   //高度库数
        index += 4;
        int w = BitConverter.toInt32(bytes, index);   //水平库数
        index += 4;
        float startJL = BitConverter.toFloat(bytes, index);
        index += 4;
        float startFW = BitConverter.toFloat(bytes, index);
        index += 4;
        float endZZ = BitConverter.toFloat(bytes, index);
        index += 4;
        float endFW = BitConverter.toFloat(bytes, index);
        index += 4;
        float yj = BitConverter.toFloat(bytes, index);
        index += 4;
        _this.data = new double[h][w];
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                char c = BitConverter.toChar(bytes, index);
                long d = Integer.toUnsignedLong(c);
                if (_this.header.realObserSec.iProductNumber == 9) {
//                    _this.data[i][j] = (double) ((d - 64)) / 2.0;;
//                    _this.data[i][j] = _this.data[i][j] < -10 || _this.data[i][j] > 900 ? GisConstants.UNDEF : _this.data[i][j];
                    _this.data[i][j] = d;
                } else {
//                    _this.data[i][j] = d == 0 ? GisConstants.UNDEF : (double) ((d - 129)) * 0.5;
                    _this.data[i][j] = d;
                }
                index += 1;
            }
        }
    }
}
